package engine

import "gateway/core"

type inboundChain struct {
	inbounds []inboundRuntime
}

func newInboundChain(inbounds []inboundRuntime) core.InboundChain {
	return &inboundChain{
		inbounds: inbounds,
	}
}

func (this *inboundChain) Dispatch(msg core.Message) bool {
	if len(this.inbounds) == 0 {
		return false
	}

	flag := false
	for _, in := range this.inbounds {
		if in.inbound.Receive(msg) {
			flag = true
		}
	}
	return flag
}

func (this *inboundChain) GetInbounds() []core.Inbound {
	inbounds := make([]core.Inbound, len(this.inbounds))
	for i, in := range this.inbounds {
		inbounds[i] = in.inbound
	}
	return inbounds
}
